import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//计网局域异步通信作业
public class NetCode {
    public static void main(String[] args) {
        int size;
        System.out.println("输入要传输的字符串");
        Scanner in = new Scanner(System.in);
        String msg= in.nextLine();
        List<Double> volts= rs232c_encode(msg);
        System.out.println(volts);
        System.out.println("解码后的信息如下");
        String res =rs232c_decode(volts);
        System.out.println(res);
    }

    public static List<Double> rs232c_encode(String msg){
        List<Double> volts= new ArrayList<>();
        for(int i=0;i<msg.length();i++){
            volts.add(15.0);
            char c=msg.charAt(i);
            for(int j=0;j<7;j++){
               if(((c>>j)&1)==1){
                   volts.add(-15.0);
               }
               else volts.add(15.0);
            }
            volts.add(-15.0);
        }
        return volts;
    }

    public static String rs232c_decode(List<Double> volts){
        String msg= new String();
        for(int i=0;i<volts.size();i++){
            if(volts.get(i)<0) continue;
            char c=0;
            for(int j=0;j<7;j++){
                if(volts.get(i+j+1)<0) c|= (char) (1<<j);
            }
            msg+=c;
            i+=7;
        }
        return msg;
    }
}
